<template>
  <div ref="line" class="box"></div>
</template>

<script>
import * as echarts from "echarts";
export default {
  props: {
    xData: {
      type: Array,
      default: () => [],
    },
    yData: {
      type: Array,
      default: () => [],
    },
  },
  data() {
    return {
      myChart: null,
    };
  },
  methods: {
    draw() {
      if (this.myChart === null) {
        //第二步 初始化 echarts
        this.myChart = echarts.init(this.$refs.line);
      }

      //第三步绘制图表
     this.myChart.setOption({
        title: {
          text: "ECharts 入门示例",
        },
        legend: {},
        tooltip: {},

        xAxis: {
          data: this.xData,
        },
        yAxis: {},
        series: this.yData.map((item) => {
          item.type = "line";
          return item;
        }),
      });
    },
  },

  watch: {
    xData: {
      handler: function () {
        this.draw();
      },

      deep: true,
    },
  },
};
</script>

<style lang="less" scoped>
.box {
  width: 100%;
  height: 100%;
}
</style>